<template>
	<view class="wrap">
		<view class="logo u-col-center" style="display: flex;text-align: center;justify-content: center; ">

			<u-image width="80rpx" height="80rpx" :src="'/static/aidex/images/logo.png'" shape="circle" style="background-color: #a5d0ff;box-shadow: 3px -1px 1px #ff70019c;margin-right: 15rpx;padding: 1px;"></u-image>	
			PEGASUS
			</view>
		<view class="second">工艺数据管理系统</view>
		<div v-if="loginType === 'currentPhone'">
	
		<view v-if="current === 0">
			<view class="list">
				<view class="list-call">
					<view class="iconfont icon-avatar" style="font-size: 22px;color:#5473e8;"></view>
					<input class="u-input" type="text" v-model="username" maxlength="32" :placeholder="$t('login.placeholderAccount')" value="admin"/>
					
				</view>
				<view class="list-call">
					<view class="iconfont icon-key" style="font-size: 22px;color:#5473e8;"></view>
					<input class="u-input" type="text" v-model="password" maxlength="32" :placeholder="$t('login.placeholderPassword')" :password="!showPassword" value="admin123" />
					<image class="u-icon-right" :src="'/static/aidex/login/eye_' + (showPassword ? 'open' : 'close') + '.png'" @click="showPass()"></image>
				</view>
				<div style="padding:15rpx 0 0;">
					<view class="register">
						<!-- <navigator class="register-link" url="forget" open-type="navigate">{{$t('login.forget')}}</navigator> -->
						<!-- <navigator class="register-link" url="reg" open-type="navigate">{{$t('login.reg')}}</navigator> -->
					</view>
					<u-checkbox v-model="remember" active-color="#5473e8">{{$t('login.autoLogin')}}</u-checkbox>
				</div>
			</view>
			<view class="button"  @click="submit('1')"><text>登录</text></view>
			<view class="login-bottom-box">
				<u-divider> 越野车装配厂 </u-divider>
				
				<view class="copyright">
					登录即代表您已阅读并同意<u-link href="#">用户协议</u-link> 与 <u-link href="#">隐私政策</u-link>
				</view>
			</view>
		</view>
	
		</div>
		

		
	</view>
</template>
<script>
/**
 * Copyright (c) 2013-Now http://aidex.vip All rights reserved.
 */
import base64 from '@/common/base64.js';
// var loginPage="/pages/sys/msg/index";
export default {
	data() {
		return {
			phoneNo:'',
			username: '',
			password: '',
			loginType: 'currentPhone', 
			showPassword: false,
			remember: true,
			isValidCodeLogin: false,
			validCode: '',
			imgValidCodeSrc: null,
			list: [{name: '用户名'}, {name: '手机号'}],
			current: 0,
			activeColor: '#007aff',
			loginPage:'/pages/sys/home/index',
			wgtVer:'',
			version:''
		};
	},
	onLoad() {
		// uni.reLaunch({
		// 	url: this.loginPage
		// });1111
		this.plusReady()
		// this.$u.api.check().then(res => {
		// 	if (res.code === 200){
		// 		uni.reLaunch({
		// 			url: this.loginPage
		// 		});
		// 	}else{
		// 		console.log(res)
		// 	}
		// });
		this.AndroidCheckUpdate()
		},
	methods: {
		 // 获取当前版本号
		 plusReady(){
			 var that = this;
		
			                 // 获取本地应用资源版本号 1 
			                 plus.runtime.getProperty(plus.runtime.appid,function(inf){
								 
								 // console.log(inf)
			                     that.wgtVer = inf.versionCode;  //获取当前版本号1111111
			                     that.version = plus.runtime.versionCode; 
			                 });
							 
						this.$u.toast("plus.runtime.appid："+plus.runtime.versionCode);
						// this.$u.toast("plus.runtime.wgtVer："+plus.runtime.wgtVer);
						// this.$u.toast("plus.runtime.version："+plus.runtime.version);
							
		 },
		 
		 

		 
		 AndroidCheckUpdate(){
			 this.$u.api.getAndroidVersion().then(res => {
			console.log(res.msg)
			console.log("res.data.version:"+res.data.version)
			console.log("this.version:"+this.wgtVer)
			 	if (res.data.version!=this.wgtVer){
				console.log("asd")
			 		 if(plus.networkinfo.getCurrentType()!=3){  
			 		                                uni.showToast({  
			 		                                    title: '有新的版本发布，检测到您目前非Wifi连接，为节约您的流量，程序已停止自动更新，将在您连接WIFI之后重新检测更新。',  
			 		                                    mask: false,  
			 		                                    duration: 5000,  
			 		                                    icon:"none"  
			 		                                });  
			 		                                return;  
			 		}  
			 		                            uni.showToast({  
			 		                                title: '有新的版本发布，检测到您目前为Wifi连接，程序已启动自动更新。新版本下载完成后将自动弹出安装程序。',  
			 		                                mask: false,  
			 		                                duration: 5000,  
			 		                                icon:"none"  
			 		                            });  
			 	
				
				 var dtask = plus.downloader.createDownload(res.data.url, {}, function ( d, status ) {  
				                                    // 下载完成  
				                                    if ( status == 200 ) {   
				                                        plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename),{},{},function(error){  
				                                            uni.showToast({  
				                                                title: '安装失败',  
				                                                mask: false,  
				                                                duration: 1500  
				                                            });  
				                                        })  
				                                    } else {  
				                                         uni.showToast({  
				                                            title: '更新失败',  
				                                            mask: false,  
				                                            duration: 1500  
				                                         });  
				                                    }    
				                                });  
				                                dtask.start();   
				                          
		
			 	}else{
			 		console.log(res)
			 	}
			 });
		 },
		showPass() {
			this.showPassword = !this.showPassword;
		},
		qiehuanLogin(){
			this.loginType = 'other'
		},
		onClickItem(index) {
							this.current = index;
					},
		refreshImgValidCode(e) {
			if (this.vuex_token == '') {
				this.$u.api.index().then(res => {
					this.imgValidCodeSrc = this.vuex_config.baseUrl + '/validCode?__sid='
						+ res.sessionid + '&t=' + new Date().getTime();
				});
			} else {
				this.imgValidCodeSrc = this.vuex_config.baseUrl + '/validCode?__sid='
						+ this.vuex_token + '&t=' + new Date().getTime();
			}
			this.validCode = '';
		},
		nextStep(){
			//验证码登录下一步
			uni.showLoading({
								title: '正在获取验证码',
								mask: true
							})
			this.$u.api.sendCode({
				phoneNo: this.phoneNo,
				validCodeType:'2'
			})
			.then(res => {
				if (res.code == '200') {
					setTimeout(() => {
						uni.navigateTo({
							url: '/pages/sys/login/code?phoneNo='+this.phoneNo
						});
					}, 500);
				}else{
					this.$u.toast(res.msg);
					setTimeout(() => {
						uni.navigateTo({
							url: '/pages/sys/login/code?phoneNo='+this.phoneNo
						});
					}, 500);
				}
			});
		},
		submit(loginType) {
			
			// uni.reLaunch({
			// 	url: this.loginPage
			// });
			
			
			if (this.username.length == 0) {
				this.$u.toast('请输入账号');
				return;
			}
			if (this.password.length == 0) {
				this.$u.toast('请输入密码');
				return;
			}
			this.$u.api.login({
				username: this.username,
				password: this.password,
				validCode: this.validCode,
				loginType: loginType
			})
			.then(res => {
				if(res.msg){
					this.$u.toast(res.msg);
				}
				if (res.code == '200') {
					setTimeout(() => {
						uni.reLaunch({
							url: this.loginPage
						});
					}, 500);
				}
				if (res.isValidCodeLogin){
					this.isValidCodeLogin = true;
					this.refreshImgValidCode();
				}
			});
		}
	}
};
</script>
<style lang="scss">
@import 'index.scss';

.logo {
	width: 80%;
	font-size:64rpx;
	color: #5473e8;
	margin: 80rpx auto 5rpx auto;
	text-align: center;
}
.second{
	font-size: 24rpx;
	color:$u-tips-color;
	letter-spacing:3rpx;
	font-weight: bold;
	margin: 5rpx auto 70rpx auto;
	
}
.list-call-icon{
	color: #ff0000;
}
.currentPhone-box{
	text-align: center;
	padding: 40rpx 80rpx;
	.number-text{
		color: #000000;
		font-size: 60rpx;
	}
	.other-text{
		color: #999999;
		font-size: 26rpx;
		padding: 20rpx 0;
	}
	.u-btn{
		margin: 30rpx auto;
	}
	.u-hairline-border{
	    border: 1px solid #fff;
	}
}

.register {
	display:inline-block;
	color: #5473e8;
	height: 40rpx;
	line-height: 40rpx;
	font-size: 28rpx;
	float:right;
	margin-top: 6rpx;
}
.register-link{
	float: right;
	padding: 0 16rpx;
}
.reg-link{
	display: inline-block;
	color: #5473e8;
}
.oauth2 {
	display: flex;
	flex-direction: row;
	justify-content: space-around;
	margin: 0rpx 100rpx 30rpx;

	image {
		height: 80rpx;
		width: 80rpx;
	}
}
.u-tabs{
	padding: 0 70rpx;
}

</style>
